// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_RESOURCE_MANAGER__
#define __H_MK_RESOURCE_MANAGER__

#include "mk_render_define.h"
#include "mk_resource.h"

namespace MK3DE
{
	class CTexture2D;
	class CTexture3D;
	class CMesh;
	class CShader;
	class CFTFont;
	class CSkeletonData;
	class CImage;
	class CHardwareBuffer;

	class MK3DE_API CResourceManager
	{
	public:
		CResourceManager();
		~CResourceManager();

		BOOL Create();
		void Destroy();

		//! texture
		BOOL GetTexture2DFromFile(const char* fileName, CTexture2D*& pTexture);
		BOOL GetTexture2DFromMemory(const BYTE buffer[], DWORD size, CTexture2D*& pTexture);
		BOOL GetTexture2D(DWORD width, DWORD height, PIXEL_FORMAT format, DWORD mip, TEXTURE_USAGE usage, /* out */ CTexture2D*& pTexture);
		BOOL GetTexture3DFromFile(const char* fileName, CTexture3D*& pTexture);

		//! Mesh
		BOOL GetMesh(const char* fileName, CMesh*& pMesh);

		//! Shader
		BOOL GetShaderFromFile(const char* fileName, CShader*& pShader);
		BOOL GetShaderFromMemory(const BYTE buffer[], DWORD size, CShader*& pShader);

		//! FreeType font.
		BOOL GetFTFont(const char* fileName, BOOL bAntialiased, DWORD points, CFTFont*& pFont);

		//! Skeleton data.
		BOOL GetSkeletonData(const char* fileName, CSkeletonData*& pSkeletonData);

		//! Image.
		BOOL GetImage(const char* fileName, CImage*& pImage);

		//! Hardware buffer.
		BOOL GetVertexBuffer(DWORD vertexSize, DWORD vertexNum, HARDWARE_BUFFER_USAGE usage, CHardwareBuffer*& vertexBuffer);
		BOOL GetIndexBuffer(DWORD indexNum, INDEX_TYPE indexType, HARDWARE_BUFFER_USAGE usage, CHardwareBuffer*& indexBuffer);

		BOOL OnResourceDelete(CResource* res);
		BOOL RemoveAllResource();

		//! Reload resources.
		void ReloadAllResource();
		void ReloadResource(RESOURCE_TYPE type);

	private:
		CResource* GetResourceByName(RESOURCE_TYPE type, const char* name);

	private:
		//!< Named resource hash map.
		stdext::hash_map<std::string, CResource*>    _resMapList[RES_T_MAX];

		//!< Nameless resource list.
		std::list<CResource*>   _namelessResList[RES_T_MAX];

	};
};

#endif // __H_MK_RESOURCE_MANAGER__